package com.bjSoft.regressionTestTool.codeCoverage;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.IPath;

import com.bjSoft.regressionTestTool.codeCoverage.base.ClassCoverageInfo;
import com.bjSoft.regressionTestTool.codeCoverage.base.MethodCoverage;
import com.bjSoft.regressionTestTool.util.ArquivoSaida;

public class CoverageMatrixWriter {	
	public static void writeMatrix(HashMap<String, ClassCoverageInfo> coverageData,
			IPath filePath) {
		ArquivoSaida arquivoSaida =
			new ArquivoSaida(filePath.toOSString() + "\\coverageFile.txt");
		
		Set<String> allClass = coverageData.keySet();
		
		Iterator<String> it = allClass.iterator();
		while (it.hasNext()) {
			String className = it.next();
			ClassCoverageInfo covInfo = coverageData.get(className);
			arquivoSaida.println("CLASS_" + className);
			HashMap<String, MethodCoverage> methods = covInfo.getMethods();
			Set<String> methodsNames = methods.keySet();
			Iterator<String> methodsNameIt = methodsNames.iterator();
			while (methodsNameIt.hasNext()) {
				String methodName = methodsNameIt.next();
				MethodCoverage methodCov = methods.get(methodName);
				arquivoSaida.println("\tMETHOD_" + methodCov.getMethodName());
				List<String> testCases = methodCov.getTestCases();
				Iterator<String> testCasesNamesIT = testCases.iterator();
				while (testCasesNamesIT.hasNext()) {
					String testCaseName = testCasesNamesIT.next();
					arquivoSaida.println("\t\t " + testCaseName);
				}
				arquivoSaida.println("\tENDMETHOD_" + methodName);
				arquivoSaida.println();
			}
			arquivoSaida.println("ENDCLASS_" + className);			
			arquivoSaida.println();
			arquivoSaida.println();
		}
		arquivoSaida.println("ENDFILE");	
		arquivoSaida.close();
	}
}
